<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*,com.test.bean.*"%> 
<%@taglib  uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path ;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="<%=path %>/easyui/themes/default/easyui.css">   
<link rel="stylesheet" type="text/css" href="<%=path %>/easyui/themes/icon.css">   
<script type="text/javascript" src="<%=path %>/easyui/jquery.min.js"></script>   
<script type="text/javascript" src="<%=path %>/easyui/jquery.easyui.min.js"></script> 
<title>Insert title here</title>
<script>
//退出
function logout()
{
	var url = "<%=path %>/login.jsp";
	window.open(url,'_self');
}
//定义Datagrid单元格显示,将文本显示为按钮
function formatOper(val,row,index){
	if(val == '0')
		return '<input type="checkbox" name="checkbox" value="'+row.id+'">喜欢</input>&nbsp;';
	else
    	return '<img src="<%=path %>/like.png"/>';
}
//修改图书
function editBook(val)
{
	var rows = $('#dg').datagrid('getRows');
	var selRow = rows[val];
	$('#wid').val(selRow.id);
	$('#wname').textbox('setValue',selRow.name);
	$('#wauthor').textbox('setValue',selRow.author);
	$("input[name='wcatagory']").each(function(){ 
		if($(this).val() == selRow.catagory)
			$(this).attr("checked",true);
		else
			$(this).attr("checked",false);
	});
	$('#win').window('open');
}
//添加新图书,图书ID置空
function addNewBook()
{
	$("#wid").val('');
	$('#win').window('open');
}
//删除图书操作
function delBook(val)
{
	var rows = $('#dg').datagrid('getRows');
	var selRow = rows[val];
	$('#did').val(selRow.id);
	$('#delwin').window('open');
}
//关闭新建,修改窗口
function closewin()
{
	$('#win').window('close');
}
//新建,修改窗口上保存按钮操作
function save()
{
	var aa='';
	$("input[name='checkbox']:checkbox:checked").each(function(){ 
		aa+=$(this).val()+','; 
	});

	$.ajax({  
        url : '<%=path %>/book/userlike?chkid='+aa,  
        type:"post",
        success : function(result) {  
        	$('#dg').datagrid({   
        	    url:'<%=path %>/book/userbook'
       	});
        }  
    }); 	
	
}
</script>
</head>
<body>
<input type="button" value="退出" onclick="logout()"/>

<table id="dg" title="图书信息" class="easyui-datagrid"  
            url="<%=path %>/book/userbook"  
            toolbar="#toolbar" pagination="true" pageList="[4]" pageSize="4"
            rownumbers="false" fitColumns="true" singleSelect="true">  
        <thead>  
            <tr>  
                <th data-options="field:'id',sortable:true,width:20">图书ID</th>  
                <th data-options="field:'name',width:20">图书名</th>  
                <th data-options="field:'catagory',width:20">类别</th>  
                <th data-options="field:'author',width:20">作者</th>  
                <th data-options="field:'flag',width:80,align:'center',formatter:formatOper">操作</th>  
            </tr>
        </thead>  
</table> 
<form id="queryForm" method="post">
	<div style="margin-bottom:20px">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="save()" style="width:80px">确定</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="addNewBook()" style="width:80px">关闭</a>
	</div>
</form>

</body>
</html>